import { getCate } from "@/utils/api/headerapi";
let topCategory = [
    "居家",
    "美食",
    "服饰",
    "母婴",
    "个护",
    "严选",
    "数码",
    "运动",
    "杂项",
]
export default {
    namespaced: true,
    state: {
        //给数据前面加name属性
        cate: topCategory.map(item => { return { name: item } }),
        nowcateindex: null
    },
    mutations: {
        //设置cate
        setCate(state, arr) {
            state.cate = arr
        },
        setCateIndex(state, key) {
            state.nowcateindex = key
        }
    },
    actions: {
        //调用api拿到数据
        async asyncSetCate({ commit }) {
            let res = await getCate()
            // console.log(res);
            commit('setCate', res.result)
        }
    }
}